package com.learn.thread;

/**
 * 线程停止案例
 */
public class TestThreadStop implements Runnable{

    private volatile boolean flag = true;
    @Override
    public void run() {
        int i = 1;
        while (flag){
            System.out.println("子线程-------->"+i++);
        }
    }
    public void stop() {
        flag = false;
    }

    public static void main(String[] args) {
        TestThreadStop testThreadStop = new TestThreadStop();
        new Thread(testThreadStop).start();
        for (int i = 0; i < 10000; i++) {
            System.out.println("主线程---->" + i);
            if (i==9000){
                testThreadStop.stop();
                break;
            }

        }
    }
}
